#include "WindowsServiceHelper.h"
#include <windows.h>
#include <Sstream>
#include <QDIr>
#include <QDebug>

WindowsServiceHelper::WindowsServiceHelper()
{

}

void WindowsServiceHelper::SetDesktopWallpaper(QString imageName)
{
    qDebug()<<"SetDesktopWallpaper "<<QDir::currentPath().append("/").append(imageName);
    const char *tmp = QDir::currentPath().append("/imageCache/").append(imageName).toStdString().c_str();
    std::wstringstream wss; //主要是用来转换格式的：从const char* 转换到 const wchar_t*，因为SystemParameterInfo需要接收wchar_t类型的参数，不然会设置失败
    wss << tmp;
    const wchar_t *filename = wss.str().c_str();
    if(SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)filename, SPIF_UPDATEINIFILE) == FALSE) //设置桌面背景
    {
        qDebug() << "Set background image fail";
    }
    else
    {
        qDebug() << "Set background success";
    }
}

